Cheddar

Cheddar Introduction

# load package
library(cheddar)
# load data
data(TL84)

A community data set in cheddars framework has 3 components. Cheddar works best if you import your 3 components from 3 seperate CSVs into a directroy and then that directory name will be your dataset name.

To illustrate the cheddar data framework we are going to break down Tuesday Lakes data set into the 3 CSVs.

Properties

Contains properties applicable to the community.
- Must contain one row of data and title column
- M & N units must be present if they are present in the nodes csv

# First we are going to make a directory to hold the csvs
# create community directory
dir.create("TL84")
# create vectors
title = "Tuesday Lake sampled in 1984"
N.units = "m^-3"
M.units = "kg"
lat = 46.21667
long = 89.53333
habitat = "Freshwater pelagic"
# making a data frame with vectors 
properties<-data.frame(title, N.units, M.units, lat, long, habitat)
properties
##                          title N.units M.units      lat     long
## 1 Tuesday Lake sampled in 1984    m^-3      kg 46.21667 89.53333
##              habitat
## 1 Freshwater pelagic
## write csv #row.names=FALSE the column names wouldnt line up
write.csv(properties, file="TL84/properties.csv", row.names=FALSE)

Nodes

Defines species and associated properties
- Contains one row for every species in the community
- Node column is the only mandatory column
+ Column node contains node or species names
+ M & N represent Mass & Numerical Abundance

# create nodes.csv for cheddar
node = TL84$nodes$node
# category = TL84$nodes$category
# Cheddar has a really nice function to collapse the community by any of these categories
M = TL84$nodes$M
N = TL84$nodes$N
kingdom = TL84$nodes$kingdom
phylum = TL84$nodes$phylum
class = TL84$nodes$class
order = TL84$nodes$order
family = TL84$nodes$family
genus = TL84$nodes$genus
species = TL84$nodes$species
# making a data frame with vectors 
nodes<-data.frame(node,
                  M, N, kingdom, phylum, class, order, family, genus, species)
head(nodes)
##                    node        M       N   kingdom        phylum
## 1            Nostoc sp. 7.97e-13 2.0e+06  Bacteria Cyanobacteria
## 2      Arthrodesmus sp. 1.52e-12 4.9e+07   Plantae    Charophyta
## 3  Asterionella formosa 1.12e-12 5.0e+06 Chromista    Ochrophyta
## 4     Cryptomonas sp. 1 2.03e-13 6.4e+07 Chromista   Cryptophyta
## 5     Cryptomonas sp. 2 1.51e-12 2.8e+07 Chromista   Cryptophyta
## 6 Chroococcus dispersus 2.39e-13 2.0e+07  Bacteria Cyanobacteria
##               class           order           family        genus
## 1      Cyanophyceae      Nostocales      Nostocaceae       Nostoc
## 2  Zygnematophyceae     Desmidiales     Desmidiaceae Arthrodesmus
## 3 Bacillariophyceae   Fragilariales   Fragilariaceae Asterionella
## 4     Cryptophyceae Cryptomonadales Cryptomonadaceae  Cryptomonas
## 5     Cryptophyceae Cryptomonadales Cryptomonadaceae  Cryptomonas
## 6      Cyanophyceae   Chroococcales   Chroococcaceae  Chroococcus
##     species
## 1          
## 2          
## 3   formosa
## 4          
## 5          
## 6 dispersus
##write csv
write.csv(nodes, file="TL84/nodes.csv", row.names=FALSE)

Abundance vs Mass (Network Connection Overlay) Plot

# Plot 1 species
PlotNvM(TL84, col=1, pch=19, highlight.nodes=NULL, show.web=FALSE) # can easily do without cheddar

PlotNvM(TL84, col=1, pch=19, highlight.nodes=NULL, show.web=TRUE)

PlotNvM(TL84, col=1, pch=19, highlight.nodes='Daphnia pulex')

PlotNvM(TL84, col=1, pch=19, highlight.nodes='Daphnia pulex', 
  highlight.links=TrophicLinksForNodes(TL84, 'Daphnia pulex'))

# Plot 2 species
PlotNvM(TL84, col=1, pch=19, highlight.nodes=c('Daphnia pulex','Trichocerca cylindrica'))

PlotNvM(TL84, col=1, pch=19, highlight.nodes=c('Daphnia pulex','Trichocerca cylindrica'), 
  highlight.links=TrophicLinksForNodes(TL84, c('Daphnia pulex','Trichocerca cylindrica')))

Food-Web By Level Plot

 # Compare prey-averaged and chain-averaged trophic level
    par(mfrow=c(1,2)) # setting up 2 plots
    PlotWebByLevel(TL84, ylim=c(1,5.8),level='PreyAveragedTrophicLevel', main='Prey-averaged',col=1, pch=19,           highlight.nodes=NULL) # the mean trophic level of the node's resources, using the matrix inversion method of Levine (1980)
    PlotWebByLevel(TL84, ylim=c(1,5.8), level='ChainAveragedTrophicLevel',col=1, pch=19, highlight.nodes=NULL,
                   main='Chain-averaged') # 1 plus the average chain length of all paths from each node to a basal species

    # Compare the three different x layouts
    par(mfrow=c(1,3))
    for(x.layout in c('skinny', 'narrow', 'wide'))
    {
        PlotWebByLevel(TL84, x.layout=x.layout, main=x.layout, col=1, pch=19, highlight.nodes=NULL)
    }

    # Compare the effect of staggering levels
    # Primary producers are staggered in the second plot
    par(mfrow=c(1,2))
    # No staggering - stagger and max.nodes.per.row are ignored
    PlotWebByLevel(TL84, y.layout='compress',col=1, pch=19)
    # Stagger
    PlotWebByLevel(TL84, y.layout='stagger', stagger=0.1,col=1, pch=19,
                   max.nodes.per.row=20)

    # Highlight pulex
        PlotWebByLevel(TL84, y.layout='stagger', stagger=0.1,col=1, pch=19,highlight.nodes='Daphnia pulex',
                   max.nodes.per.row=20)  # just node
        PlotWebByLevel(TL84, y.layout='stagger', stagger=0.1,col=1, pch=19, highlight.nodes='Daphnia pulex', highlight.links=TrophicLinksForNodes(TL84, 'Daphnia pulex'), max.nodes.per.row=20) # node and trophic links

Kingdom Level Regression

# custom symbols for each kingdom
symbol.spec = c(Bacteria=21, Plantae=22, Chromista=23,
                 Protozoa=24, Animalia=25, 19)
symbol.spec
##  Bacteria   Plantae Chromista  Protozoa  Animalia           
##        21        22        23        24        25        19
colour.spec = c(Bacteria='purple3', Plantae='green3', Chromista='blue3', Protozoa='orange3',
Animalia='red3', 'black')
# run plot and legend at same time
PlotNvM(TL84,
symbol.by='kingdom', symbol.spec=symbol.spec, bg.by='kingdom', bg.spec=colour.spec, colour.by='kingdom', colour.spec=colour.spec, highlight.nodes=NULL)
legend("topright", legend=names(colour.spec), pch=symbol.spec,
        col=colour.spec, pt.bg=colour.spec)

#Run all at once (different regression lines for desnity and biomass for diff kingdoms)
PlotNvM(TL84,
symbol.by='kingdom', symbol.spec=symbol.spec, bg.by='kingdom', bg.spec=colour.spec, colour.by='kingdom', colour.spec=colour.spec, highlight.nodes=NULL, show.web=FALSE)
legend("topright", legend=names(colour.spec), pch=symbol.spec,
        col=colour.spec, pt.bg=colour.spec)
models <- NvMLinearRegressions(TL84, class='kingdom')
colours <- PlotLinearModels(models, colour.spec=colour.spec)

Lumping Communities

# Lumping community by order
# Create vector desginating lumpage
lump <- NP(TL84, 'order') # NP extracts node/species property
head(lump, 20)
##                    Nostoc sp.              Arthrodesmus sp. 
##                  "Nostocales"                 "Desmidiales" 
##          Asterionella formosa             Cryptomonas sp. 1 
##               "Fragilariales"             "Cryptomonadales" 
##             Cryptomonas sp. 2         Chroococcus dispersus 
##             "Cryptomonadales"               "Chroococcales" 
##     Closteriopsis longissimus   Chrysosphaerella longispina 
##                "Chlorellales"               "Chromulinales" 
##           Dinobryon bavaricum         Dinobryon cylindricum 
##               "Chromulinales"               "Chromulinales" 
## Dactylococcopsis fascicularis                   Diceras sp. 
##               "Chroococcales"                "Hibberdiales" 
##    Dictyosphaerium pulchellum          Dinobryon sertularia 
##                "Chlorellales"               "Chromulinales" 
##             Dinobryon sociale        Glenodinium quadridens 
##               "Chromulinales"                "Peridiniales" 
##        Microcystis aeruginosa              Mallomonas sp. 1 
##               "Chroococcales"                   "Synurales" 
##              Mallomonas sp. 2      Unclassified flagellates 
##                   "Synurales"                            ""
# rename parts of vector with "" for order name.
lump[""==lump] <- names(lump[""==lump] )
head(lump, 20)
##                    Nostoc sp.              Arthrodesmus sp. 
##                  "Nostocales"                 "Desmidiales" 
##          Asterionella formosa             Cryptomonas sp. 1 
##               "Fragilariales"             "Cryptomonadales" 
##             Cryptomonas sp. 2         Chroococcus dispersus 
##             "Cryptomonadales"               "Chroococcales" 
##     Closteriopsis longissimus   Chrysosphaerella longispina 
##                "Chlorellales"               "Chromulinales" 
##           Dinobryon bavaricum         Dinobryon cylindricum 
##               "Chromulinales"               "Chromulinales" 
## Dactylococcopsis fascicularis                   Diceras sp. 
##               "Chroococcales"                "Hibberdiales" 
##    Dictyosphaerium pulchellum          Dinobryon sertularia 
##                "Chlorellales"               "Chromulinales" 
##             Dinobryon sociale        Glenodinium quadridens 
##               "Chromulinales"                "Peridiniales" 
##        Microcystis aeruginosa              Mallomonas sp. 1 
##               "Chroococcales"                   "Synurales" 
##              Mallomonas sp. 2      Unclassified flagellates 
##                   "Synurales"    "Unclassified flagellates"
#create lumped community dataset
TL84.lumped <- LumpNodes(TL84, lump)
TL84.lumped
## Tuesday Lake sampled in 1984 (lumped) containing 22 nodes and 58 trophic links
# were gonna make 4 plots to NvM 1 not lumped and 1 lumped
par(mfrow=c(2,2))
PlotNvM(TL84, col=1, pch=19, highlight.nodes=NULL)
PlotNvM(TL84.lumped, col=1, pch=19, highlight.nodes=NULL)
PlotWebByLevel(TL84, y.layout='stagger', stagger=0.1,col=1, pch=19,
                   max.nodes.per.row=20)
PlotWebByLevel(TL84.lumped, y.layout='stagger', stagger=0.1,col=1, pch=19,
                   max.nodes.per.row=20)

Chesapeake Bay Data, Symbolizing Nodes & Lengths

# ChesapeakeBay Data
data(ChesapeakeBay)
ChesapeakeBay$properties
## $title
## [1] "Chesapeake Bay"
## 
## $habitat
## [1] "Mesohaline"
# Quantitative descriptors of the Food web as a whole
QuantChesapeakeBay<-QuantitativeDescriptors(ChesapeakeBay, 'biomass.flow')
head(QuantChesapeakeBay)
##                           Qualitative Unweighted   Weighted
## Fraction top level         0.36363636 0.36363636 0.45454545
## Fraction intermediate      0.48484848 0.48484848 0.39393939
## Fraction basal             0.15151515 0.15151515 0.15151515
## Ratio resources:consumers  0.75000000 0.71137339 0.31666107
## Link density               2.21212121 1.37193351 2.09605591
## Connectance                0.06703398 0.04157374 0.06351685
# Quantitative descriptors of each node.
NodeChesapeakeBay<-NodeQuantitativeDescriptors(ChesapeakeBay, 'biomass.flow')
head(NodeChesapeakeBay)
##                                          NResources NConsumers   bIn
## Phytoplankton                                     0          7     0
## Bacteria attached to suspended particles          0          8     0
## Sediment bacteria                                 0          6     0
## Benthic algae                                     0          1     0
## Free bacteria in water column                     0          1     0
## Heterotrophic microflagellates                    1          1 88721
##                                              bOut nN       nP d.prime
## Phytoplankton                             80050.8  0 3.191454     0.0
## Bacteria attached to suspended particles   2977.0  0 3.213943     0.0
## Sediment bacteria                        294954.9  0 3.632425     0.0
## Benthic algae                             18086.0  0 1.000000     0.0
## Free bacteria in water column             88721.0  0 1.000000     0.0
## Heterotrophic microflagellates            31638.0  1 1.000000     0.5
##                                                  d o.prime o   g.prime
## Phytoplankton                            0.0000000       0 0 0.0000000
## Bacteria attached to suspended particles 0.0000000       0 0 0.0000000
## Sediment bacteria                        0.0000000       0 0 0.0000000
## Benthic algae                            0.0000000       0 0 0.0000000
## Free bacteria in water column            0.0000000       0 0 0.0000000
## Heterotrophic microflagellates           0.7371364       0 0 0.6544422
##                                                 g   v.prime          v
## Phytoplankton                            0.000000 2.6248790  5.4743804
## Bacteria attached to suspended particles 0.000000 2.6433749  0.2050206
## Sediment bacteria                        0.000000 2.9875645 22.9579397
## Benthic algae                            0.000000 0.8224711  0.3875459
## Free bacteria in water column            0.000000 0.8224711  1.9011092
## Heterotrophic microflagellates           3.896667 0.8224711  0.6779375
# plot basic food web
PlotWebByLevel(ChesapeakeBay,
               col=1,
               pch=20,
               highlight.nodes=NULL)

# develop link line widths based on biomass flow
biomass.flow<-TLPS(ChesapeakeBay, link.properties='biomass.flow')
#create vector of biomass flow
biomass.flow<-biomass.flow[,3]
#log transform for graphical representation
link.lwd=log(biomass.flow)
#plot food web with link weights
PlotWebByLevel(ChesapeakeBay,
               col=1,
               pch=19,
               highlight.nodes=NULL,
               link.lwd=link.lwd,
               main="Chesapeake Bay Weighted by Flow"
               )

#create vector of Ratio of Prey to Consumer
cex=NodeChesapeakeBay[,5]+.01
#create vector of Ratio of Prey to Consumer Weighted by FLow
cex1=NodeChesapeakeBay[,6]+.01
 
par(mfrow=c(1,2))
PlotWebByLevel(ChesapeakeBay,
               col=1,
               pch=19,
               highlight.nodes=NULL,
               link.lwd=link.lwd,                      #FLow
               cex=cex,                                #ratio of prey to consumer
               main="CB Weighted by Flow and \nNode weighted by Ratio of Prey to Consumer"
               )
PlotWebByLevel(ChesapeakeBay,
               col=1,
               pch=19,
               highlight.nodes=NULL,
               link.lwd=link.lwd,                       #Flow
               cex=cex1,                                #ratio of prey to consumer, weighted by flow
               main="CB Weighted by Flow and \nNode weighted by Ratio of Prey to Consumer also weighted by FLow"
)

Working With Multiple Communities At ONCE

# load dataset
data("pHWebs")
pHWebs
## A collection of 10 communities
# example communities (2/10)
pHWebs$`Old Lodge`
## Old Lodge containing 23 nodes and 137 trophic links
pHWebs$`Afon Hafren`
## Afon Hafren containing 25 nodes and 135 trophic links
pHWebs$`Afon Hafren`$properties
## $title
## [1] "Afon Hafren"
## 
## $M.units
## [1] "mg"
## 
## $N.units
## [1] "m^2"
## 
## $code
## [1] "HAF"
## 
## $pH
## [1] 5.3
## 
## $lat
## [1] 52.47
## 
## $long
## [1] -3.7
## Export pHWebs to a directory
SaveCollection(pHWebs, "./comm")
## Import pHWebs from a directory
pHWebs<-LoadCollection("./comm")
 
# Biomass by Abundance for multiple communities
plot(pHWebs, col=1, pch=19, highlight.nodes=NULL)

# Food Webs for multiple communities
plot(pHWebs, plot.fn=PlotWebByLevel, col=1, pch=19, highlight.nodes=NULL)

# Returns a data.frame of first-class and computed properties of communities (Master data frame)
CollectionCPS(pHWebs)
##                             title M.units N.units code  pH   lat   long
## Afon Hafren           Afon Hafren      mg     m^2  HAF 5.3 52.47 -3.700
## Allt a'Mharcaidh Allt a'Mharcaidh      mg     m^2  MHA 6.5 57.12 -3.850
## Bere Stream           Bere Stream      mg     m^2  BER 7.5 50.73 -2.210
## Broadstone             Broadstone      mg     m^2  BRO 5.5 51.08  0.053
## Dargall Lane         Dargall Lane      mg     m^2  DAR 5.8 55.08 -4.430
## Duddon Pike Beck Duddon Pike Beck      mg     m^2 DUD1 6.1 54.41 -3.170
## Hardknott Gill     Hardknott Gill      mg     m^2 DUD2 7.0 54.40 -3.170
## Mill Stream           Mill Stream      mg     m^2  MIL 8.4 50.68 -2.180
## Mosedal Beck         Mosedal Beck      mg     m^2 DUD3 5.9 54.41 -3.140
## Old Lodge               Old Lodge      mg     m^2  OLD 5.0 51.04  0.080
## community characteristics
pH.char<-CollectionCPS(pHWebs, c('pH',                   #Community Property##i.e.: pHWebs$`Old Lodge`$properties
                                 'NumberOfNodes',        #cheddar function  ##i.e.: NumberOfNodes(pHWebs$`Old Lodge`)
                                 'NumberOfTrophicLinks', #cheddar function  ##...
                                 'DirectedConnectance',  #cheddar function  ##...
                                 'NvMSlope'))            #cheddar function  ##...
head(pH.char) 
##                   pH NumberOfNodes NumberOfTrophicLinks
## Afon Hafren      5.3            25                  135
## Allt a'Mharcaidh 6.5            40                  334
## Bere Stream      7.5            66                  943
## Broadstone       5.5            25                  178
## Dargall Lane     5.8            21                   99
## Duddon Pike Beck 6.1            35                  286
##                  DirectedConnectance   NvMSlope
## Afon Hafren                0.2160000 -0.7078312
## Allt a'Mharcaidh           0.2087500 -0.7655290
## Bere Stream                0.2164830 -0.6501359
## Broadstone                 0.2848000 -0.5853852
## Dargall Lane               0.2244898 -0.7379515
## Duddon Pike Beck           0.2334694 -0.5673022
## Node connectivity for all communities
pH.conn<-CollectionCPS(pHWebs, c('pH',              #Community Property
                        'FractionBasalNodes',       #cheddar function
                        'FractionIntermediateNodes',#cheddar function
                        'FractionTopLevelNodes',    #cheddar function
                        'FractionIsolatedNodes'))   #cheddar function
head(pH.conn) 
##                   pH FractionBasalNodes FractionIntermediateNodes
## Afon Hafren      5.3          0.4000000                 0.4800000
## Allt a'Mharcaidh 6.5          0.3500000                 0.5250000
## Bere Stream      7.5          0.3939394                 0.4393939
## Broadstone       5.5          0.3200000                 0.6000000
## Dargall Lane     5.8          0.4285714                 0.5238095
## Duddon Pike Beck 6.1          0.3714286                 0.4857143
##                  FractionTopLevelNodes FractionIsolatedNodes
## Afon Hafren                 0.12000000            0.00000000
## Allt a'Mharcaidh            0.12500000            0.00000000
## Bere Stream                 0.15151515            0.01515152
## Broadstone                  0.08000000            0.00000000
## Dargall Lane                0.04761905            0.00000000
## Duddon Pike Beck            0.14285714            0.00000000
# Plot relationships between pH and community structure.
par(mfrow=c(2,3))
with(pH.char, plot(pH, NumberOfTrophicLinks, pch=19, main="pH & NumberOfTrophicLinks", cex.lab=1.4))
with(pH.char, plot(pH, NumberOfNodes, pch=19, main="pH & NumberOfTrophicLinks", cex.lab=1.4))
with(pH.conn, plot(pH, FractionBasalNodes, pch=19, main="pH & FractionBasalNodes", cex.lab=1.4))
with(pH.conn, plot(pH, FractionIntermediateNodes, pch=19, main="pH & FractionIntermediateNodes", cex.lab=1.4))
with(pH.conn, plot(pH, FractionTopLevelNodes, pch=19, main="pH & FractionTopLevelNodes", cex.lab=1.4))
with(pH.conn, plot(pH, FractionIsolatedNodes, pch=19, main="pH & FractionIsolatedNodes", cex.lab=1.4))

# Order community by pH
pHWebs.d <- OrderCollection(pHWebs, 'pH', decreasing=TRUE)
# Plot food webs ordered by pH
plot(pHWebs.d, plot.fn=PlotWebByLevel, col=1, pch=19, highlight.nodes=NULL)